package com.ruoyi.system.service.impl;

import com.ruoyi.common.core.text.Convert;
import com.ruoyi.system.domain.SysSale;
import com.ruoyi.system.mapper.SysSaleMapper;
import com.ruoyi.system.service.ISysSaleService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * 角色信息表(SysDevice)表服务实现类
 *
 * @author makejava
 * @since 2022-03-16 10:44:32
 */
@Service
public class SysSaleServiceImpl implements ISysSaleService {

    @Resource
    private SysSaleMapper sysSaleMapper;


    @Override
    public List<SysSale> selectSaleList(SysSale sale) {
        return sysSaleMapper.queryAll(sale);
    }

    @Override
    public List<SysSale> selectSaleAll() {
        return sysSaleMapper.queryAll(new SysSale());
    }

    @Override
    public SysSale selectSaleById(Long saleId) {
        return sysSaleMapper.queryById(saleId);
    }

    @Override
    public boolean deleteSaleById(Long saleId) {
        sysSaleMapper.deleteById(saleId);
        return true;
    }

    @Override
    public int deleteSaleByIds(String ids) {
        Long[] saleIds = Convert.toLongArray(ids);
        for (Long saleId : saleIds){
            sysSaleMapper.deleteById(saleId);
        }
        return 1;
    }

    @Override
    public int insertSale(SysSale sale) {
        sale.setDelFlag("0");
        sale.setCreateTime(new Date());
        return sysSaleMapper.insert(sale);
    }

    @Override
    public int updateSale(SysSale sale) {
        sale.setUpdateTime(new Date());
        return sysSaleMapper.update(sale);
    }

    @Override
    public int changeStatus(SysSale sale) {
        return sysSaleMapper.update(sale);
    }

    @Override
    public int apply(SysSale sale) {
        sale.setStatus("0");
        sale.setDelFlag("0");
        sale.setCreateTime(new Date());
        return sysSaleMapper.insert(sale);
    }
}
